/*
 * Copyright (C) 2010-2011 sunjumper@163.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *  http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package mf.mfrpc.serialize;

import java.io.InputStream;
import java.io.OutputStream;

/**
 * 对象序列化解析器。
 */
public interface Parser {

    /**
     * 序列化对象至指定流。
     *
     * @param output 指定流对象。
     * @param object 序列化对象。
     * 
     * @throws SerializationException 如果发生序列化错误。
     */
    void writeObject(OutputStream output, Object object) throws SerializationException;

    /**
     * 从指定流中反序列化获得对象。
     *
     * @param input 指定流对象。
     *
     * @return 反序列后的对象。
     * 
     * @throws SerializationException 如果发生序列化错误。
     */
    <T> T readObject(InputStream input) throws SerializationException;

    /**
     * 从指定流中反序列化获得指定类型的对象。
     *
     * @param input 指定流对象。
     * @param type 指定的类类型。
     * 
     * @return 反序列后的对象。
     * 
     * @throws SerializationException 如果发生序列化错误。
     */
    <T> T readObject(InputStream input, Class<T> type) throws SerializationException;
}
